<?php
 defined("BASEDIR") or die();
 
 class Application_Controller_Adm_Default
 {
	protected $installedModules, $manageableModules;
	protected $controllerFilePath = "Application_Controller_Adm_";
	protected $controllerFileType = ".php";
	
	public function __construct(Application_Router_Standard_Request $request)
	{
		$view = Application_View_ViewEngine::getInstance();
		$this->getControllers();
		$this->getAdmControllers();
		$view->assign("menuitems", $this->manageableModules);
		
		if(is_readable("../application/controller/adm/".$request->action.".php"))
			$controllerName = $this->controllerFilePath.ucfirst($request->action);
		else
		{
		
			$request->action = "changelog";
			$controllerName = $this->controllerFilePath.ucfirst("changelog");
			
		}
		
		$db = Application_Model_DataBase::getInstance();
		
		
		$controller = new $controllerName($request);
		
		$view->renderadmin();
	}
	protected function getAdmControllers()
	{
		$dir = opendir("../application/controller/adm");
		while($file = readdir($dir))
		{
			if($file != "." && $file != "..")
				if(is_readable("../application/module_info/".basename($file, ".php")."info.php"))
				{
					include("../application/module_info/".basename($file, ".php")."info.php");
					$mod['name'] = basename($file, ".php");
					$this->manageableModules[] = $mod;
				}
		}
		closedir($dir);
	}
	protected function getControllers()
	{
		$dir = opendir("../application/controller");
		while($file = readdir($dir))
		{
			if($file != "." && $file != "..")
				if(is_readable("../application/module_info/".basename($file, ".php")."info.php"))
				{
					include("../application/module_info/".basename($file, ".php")."info.php");
					$mod['name'] = basename($file, ".php");
					$this->installedModules[] = $mod;
				}
		}
		closedir($dir);
	}
 }
?>